package cn.itsource.hrm.config;

/**
 * @author chenyuqi
 * @version v1.0.0
 * @date 2020/5/30
 */


import cn.itsource.util.RabbitmqConst;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {
    public static final String PAGE_QUEUE_COURSE_HOME_TEST = "page-coures-home-queue";
    /**
     * 交换机配置
     * ExchangeBuilder提供了fanout、direct、topic、header交换机类型的配置
     *
     * @return the exchange
     */
    @Bean(RabbitmqConst.PAGE_EXCHANGE_NAME)
    public Exchange EXCHANGE_TOPICS_INFORM() {
        //durable(true)持久化，消息队列重启后交换机仍然存在
        return ExchangeBuilder.directExchange(RabbitmqConst.PAGE_EXCHANGE_NAME).durable(true).build();
    }

    /**
     * 测试队列
     * @return
     */
    @Bean(PAGE_QUEUE_COURSE_HOME_TEST)
    public Queue QUEUE_INFORM_SMS() {
        Queue queue = new Queue(PAGE_QUEUE_COURSE_HOME_TEST);
        return queue;
    }

    @Bean
    public Binding BINDING_QUEUE_INFORM_SMS(@Qualifier(PAGE_QUEUE_COURSE_HOME_TEST) Queue queue,
                                            @Qualifier(RabbitmqConst.PAGE_EXCHANGE_NAME) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("page.course.home").noargs();
    }
}
